<?php
$urlAddExchangeCenter = $view->url(array(
    'controller' => 'ExchangeCenters', 'action' => 'add'));
?>
<?php if (count($view->exchangeCenters) > 0): ?>
    <?php if ($view->successInsert === true): ?>
        <div class="alert alert-success">
            El <strong>centro de intercambio</strong> se agregó exitosamente.
        </div>
    <?php endif; ?>
    <?php if ($view->successInsert === false): ?>
        <div class="alert alert-danger">
            <?php echo $view->msgError; ?>
        </div>
    <?php endif; ?>
    <div id="agregar">
        <button class="btn btn-primary" type="button">
            <span class="glyphicon glyphicon-plus"></span>
            Agregar centro de intercambio
        </button>
        <br/>
    </div>
    <div class="row">
        <div class="col-lg-6 hidden" id="nuevo">
            <form role="form" method="post" action="<?php echo $urlAddExchangeCenter; ?>">
                <div class="form-group">
                    <label for="clave">Clave</label>
                    <input type="text" class="form-control uppercase" id="clave" placeholder="Clave" name="code" required="required"/>
                </div>
                <div class="form-group">
                    <label for="nombre">Nombre</label>
                    <input type="text" class="form-control uppercase" id="nombre" placeholder="Nombre" name="name" required="required"/>
                </div>
                <div class="form-group">
                    <label for="direccion">Dirección</label>
                    <input type="text" class="form-control uppercase" id="direccion" placeholder="Dirección" name="address" required="required"/>
                </div>
                <label for="estado">Estado</label>
                <select class="form-control uppercase" id="estado" name="state">
                    <?php foreach ($view->states as $key => $state) : ?>
                        <option value="<?php echo $state->getId(); ?>"><?php echo $state->getName(); ?></option>
                    <?php endforeach; ?>
                </select>
                <br/>
                <button type="submit" class="btn btn-primary">Crear centro de intercambio</button>
                <button type="button" class="btn btn-default" id="cancelar">Cancelar</button>
            </form>
        </div>
    </div>
    <br/>
    <div class="alert alert-info">
        <p>
            Filas en <strong>rojo</strong> indican <strong>centros de intercambio inactivos
            </strong> que <strong>no</strong> pueden ser utilizados en la creación de rutas.
        </p>
        <br/>
        <button class="btn btn-default hidden" type="button" id="ocultar">
            <span class="glyphicon glyphicon-eye-close"></span> Ocultar centros de intercambio inactivos
        </button>
        <button class="btn btn-default" type="button" id="mostrar">
            <span class="glyphicon glyphicon-eye-open"></span> Mostrar centros de intercambio inactivos
        </button>
    </div>
    <table class='table table-bordered table-condensed' id='centrosDeIntercambio'>
        <thead>
            <tr>
                <th>Clave</th>
                <th>Nombre</th>
                <th>Dirección</th>
                <th>Estado</th>
                <th>Acción</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($view->exchangeCenters as $key => $exchangeCenter): ?>
                <tr class="<?php echo $exchangeCenter->getClassByStatus(); ?>" pid="<?php echo $exchangeCenter->getId(); ?>">
                    <td class="uppercase"><?php echo $exchangeCenter->getCode(); ?></td>
                    <td class="uppercase"><?php echo $exchangeCenter->getName(); ?></td>
                    <td class="uppercase"><?php echo $exchangeCenter->getAddress(); ?></td>
                    <td class="uppercase"><?php echo $exchangeCenter->getState()->getName(); ?></td>
                    <td>
                        <a data-toggle="tooltip" href="<?php
                        echo $view->url(array(
                            'controller' => 'ExchangeCenters', 'action' => 'edit',
                            'id' => $exchangeCenter->getId()));
                        ?>" title="Editar centro de intercambio">
                            <span class="glyphicon glyphicon-edit"></span>
                        </a>
                        <?php if ($exchangeCenter->getStatus() == DefaultDb_Entities_Point::STATUS_NORMAL): ?>
                            <span data-toggle="tooltip" class="glyphicon glyphicon-ok hidden pointer" title="Activar centro de intercambio"></span>
                        <?php else: ?>
                            <span data-toggle="tooltip" class="glyphicon glyphicon-ok pointer" title="Activar centro de intercambio"></span>
                        <?php endif; ?>
                        <?php if ($exchangeCenter->getStatus() == DefaultDb_Entities_Point::STATUS_CANCELED): ?>
                            <span data-toggle="tooltip" class="glyphicon glyphicon-remove hidden pointer" title="Inactivar centro de intercambio"></span>
                        <?php else: ?>
                            <span data-toggle="tooltip" class="glyphicon glyphicon-remove pointer" title="Inactivar centro de intercambio"></span>
                        <?php endif; ?>  
                    </td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
<?php else: ?>
    <div id="agregar">
        <button class="btn btn-primary" type="button">
            <span class="glyphicon glyphicon-plus"></span>
            Agregar centro de intercambio
        </button>
        <br/>
    </div>
    <div class="row">
        <div class="col-lg-6 hidden" id="nuevo">
            <form role="form" method="post" action="<?php echo $urlAddExchangeCenter; ?>">
                <div class="form-group">
                    <label for="clave">Clave</label>
                    <input type="text" class="form-control uppercase" id="clave" placeholder="Clave" name="code" required="required"/>
                </div>
                <div class="form-group">
                    <label for="nombre">Nombre</label>
                    <input type="text" class="form-control uppercase" id="nombre" placeholder="Nombre" name="name" required="required"/>
                </div>
                <div class="form-group">
                    <label for="direccion">Dirección</label>
                    <input type="text" class="form-control uppercase" id="direccion" placeholder="Dirección" name="address" required="required"/>
                </div>
                <label for="estado">Estado</label>
                <select class="form-control uppercase" id="estado" name="state">
                    <?php foreach ($view->states as $key => $state) : ?>
                        <option value="<?php echo $state->getId(); ?>"><?php echo $state->getName(); ?></option>
                    <?php endforeach; ?>
                </select>
                <br/>
                <button type="submit" class="btn btn-primary">Crear centro de intercambio</button>
                <button type="button" class="btn btn-default" id="cancelar">Cancelar</button>
            </form>
        </div>
    </div>
    <br/>
    <div class='alert alert-info'>
        <p>
            No existen centros de intercambio.
        </p>
        <p>
            Da click en el botón <strong>Agregar centro de intercambio</strong> 
            y crea uno nuevo.
        </p>
    </div>
<?php endif; ?>
